package com.gitee.jdbc.elasticsearch;

import java.sql.Types;

public enum ESFieldType {
  ID(Types.VARCHAR),
  STRING(Types.VARCHAR),
  TEXT(Types.LONGVARCHAR),
  KEYWORD(Types.VARCHAR),
  LONG(Types.BIGINT),
  INTEGER(Types.INTEGER),
  SHORT(Types.INTEGER),
  BYTE(Types.INTEGER),
  DOUBLE(Types.DOUBLE),
  FLOAT(Types.FLOAT),
  DATE(Types.DATE),
  BOOLEAN(Types.BOOLEAN),
  BINARY(Types.VARBINARY),
  INTEGER_RANGE(Types.INTEGER),
  FLOAT_RANGE(Types.FLOAT),
  LONG_RANGE(Types.BIGINT),
  DOUBLE_RANGE(Types.DOUBLE),
  DATE_RANGE(Types.DATE),
  GEO_POINT(Types.LONGVARCHAR),
  GEO_SHAPE(Types.LONGVARCHAR),

  IP(Types.LONGVARCHAR),
  COMPLETION(Types.LONGVARCHAR),
  TOKEN_COUNT(Types.LONGVARCHAR),

  ARRAY(Types.LONGVARCHAR),
  OBJECT(Types.LONGVARCHAR),
  NESTED(Types.LONGVARCHAR),
  ;

  private int jdbcType;

  ESFieldType(int jdbcType) {
    this.jdbcType = jdbcType;
  }

  public int getJdbcType() {
    return jdbcType;
  }

  public String getJdbcTypeName() {
    return JdbcTypes.resolveTypeName(jdbcType);
  }

  public static ESFieldType getESFieldType(String type) {
    if (type == null) {
      return null;
    }
    for (ESFieldType f : ESFieldType.values()) {
      if (f.name().compareTo(type.toUpperCase()) == 0) {
        return f;
      }
    }
    return null;
  }
}